﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 解释器模式
{
   public static class Translator
    {
       public static string Translate(string sentense)
       {
            var sb = new StringBuilder();
            var expressions = new List<IExpression>();
            var elements = sentense.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
           foreach (var element in elements)
           {
                var words = element.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
               foreach (var word in words)
               {
                    expressions.Add(new WordExpression(word));

                }
                expressions.Add(new SymbolExpression("."));

            }
           foreach (var expression in expressions)
           {
                expression.Interpret(sb);

            }
            return sb.ToString();

        }
    }
}
